define(['../../../carrys/md5',],function() {
    return ['$scope','$location', '$interval','$timeout','bizProxy', function($scope,$location,$interval,$timeout,bizProxy) {
    	$scope.$emit("top-show",'true');//显示顶部
    	$scope.$emit('menuTypeLight','mine'); 	//控制底部menu高亮
    	$scope.$emit('bub-menu','true'); 	//隐藏底部menu
    	$scope.$emit('flag-tag','70'); 	//显示底部文字
    	
    	//默认值
    	$scope.mobileNo = "";
    	$scope.authCode = "";
    	$scope.yzmLight = false;
    	$scope.showSend = true;
    	$scope.showTime = false;
    	$scope.isactive = false;
    	$scope.countdown = 60;
    	var tempCheckNo = "";var timeOutId;
    	
    	//监听手机号是否要高亮
    	$scope.$watch('mobileNo', function() {
    		if(($scope.mobileNo).length > 0){
    			if(($scope.mobileNo).length == 11){
        			$scope.yzmLight = true;
        		}else{
        			$scope.yzmLight = false;
        		}
        		changeStyle();
    		}
		});
    	
    	$scope.$watch('authCode', function() {
    		if(($scope.authCode + '').length > 0){
    			changeStyle();
    		}
		});
    	
    	//点击获取验证码
    	$scope.getAuthCode = function(){
    		if($scope.mobileNo != resultData.loginResultData.mobileNo){
                $scope.$emit("promptAlertMsg","手机号与原手机号不符");
                $scope.$emit("showCollect",true);
                $timeout(function(){
                    $scope.$emit("showCollect",false);
                },transData.promptTime);
    			return;
    		}
    		if(! _SYT_util.isValidNo($scope.mobileNo)){
                $scope.$emit("promptAlertMsg","手机号无效");
                $scope.$emit("showCollect",true);
                $timeout(function(){
                    $scope.$emit("showCollect",false);
                },transData.promptTime);
    			return;
    		}
    		$scope.showSend = false;
        	$scope.showTime = true;
    		getAuthCode();
    	}
    	
    	//去下一步
    	$scope.goNext = function(){
//    		验证验证码
    		if(tempCheckNo == hex_md5($scope.authCode+"")){
        		$scope.$emit('goNext','/changeNo1');
    		}else{
                $scope.$emit("promptAlertMsg","验证码错误");
                $scope.$emit("showCollect",true);
                $timeout(function(){
                    $scope.$emit("showCollect",false);
                },transData.promptTime);
    			transData.mobileCheckNo = "";
				$scope.authCode = "";
    		}
    	}
    	
    	//请求代理 获取验证码
    	function getAuthCode(){
    		startCountDown();
    		var headerInfo = {},bizInfo = {};
           	headerInfo.pageNum = '';
           	headerInfo.pageSize = '';
           	headerInfo.sessionId =transData.sessionId;
           	
           	bizInfo.mobileNo = $scope.mobileNo;
           	bizInfo.smsKind = "checkNo";
           	bizProxy.queryProxyBizData("sendCheckNo", headerInfo,bizInfo,
       				function(tempData){
       					tempCheckNo = tempData.body;
       				},
       				function(data){
                        $scope.$emit("promptAlertMsg",data.errorMsg);
                        $scope.$emit("showCollect",true);
                        $timeout(function(){
                            $scope.$emit("showCollect",false);
                        },transData.promptTime);
       				}
       		);
    	}
    	
    	//切换样式
    	function changeStyle(){
    		if(($scope.mobileNo).length == 11 && ($scope.authCode + '').length == 6){
				$scope.isactive = true;
			}else{
				$scope.isactive = false;
			}
    	}
    	
    	//开始倒计时
        function startCountDown(){
     	   timeOutId = $interval(function(){
                if (--$scope.countdown == 0){
             	   stopCountDown();
             	   $scope.countdown = 60;
             	   $scope.showSend = true;
             	   $scope.showTime = false;
                }
            }, 1000);
        }
        
        //停止倒计时
        function stopCountDown() {
     	   $interval.cancel(timeOutId);
        }
        
      //当键盘被销毁的时候
        $scope.$on("$destroy", function() {
	      	stopCountDown();
	    });
    	
    	$scope.$apply();
    }];
});